package calorie.com.calorie.contact;

import android.content.Context;

import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.ToastUtils;

import calorie.com.calorie.api.ApiService;
import calorie.com.calorie.response.BannerResponce;
import calorie.com.calorie.response.NoticeResponse;
import retrofit2.Call;
import retrofit2.Response;


public class HomeContact {
    public static class HomePresent extends BasePresent<IHomeView> {
        public void getNotice(Context context){
            ApiService service= ServiceGenerator.createService(ApiService.class);
            service.getNotice().enqueue(new NetCallBack<NoticeResponse>() {
                @Override
                public void onSuccess(Call<NoticeResponse> call, Response<NoticeResponse> response) {
                    if (getView()!=null){
                        getView().getNoticeData(response);
                    }
                }

                @Override
                public void onFailed() {

                }
            });

        }

        public void getBanner(Context context){
            ApiService service= ServiceGenerator.createService(ApiService.class);
            service.getHomeBanner().enqueue(new NetCallBack<BannerResponce>() {
                @Override
                public void onSuccess(Call<BannerResponce> call, Response<BannerResponce> response) {
                    if (getView()!=null){
                        getView().getBannerData(response);
                    }
                }

                @Override
                public void onFailed() {
                    //ToastUtils.showLongToast(context,"网络请求异常");
                }
            });
        }


    }

    public interface IHomeView extends IBaseView {
        void getNoticeData(Response<NoticeResponse> response);
      void getBannerData(Response<BannerResponce> response);
    }
}
